package com.returnsoft.softphone.eao;

import java.io.Serializable;
import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.returnsoft.softphone.exception.EaoExcepcion;

@LocalBean
@Stateless
public class QueueEao implements Serializable{
	
	private static final long serialVersionUID = 1L;
	
	@PersistenceContext(name = "CCenterEJB", unitName = "CCenterEJB")
	private EntityManager em;
	
	@SuppressWarnings("unchecked")
	public List<String> findQueues(Integer campaignId)  throws EaoExcepcion {
		try {
			Query q = em.createQuery("SELECT q.name FROM Queue q left join q.campaigns c where c.id = :campaignId");
			q.setParameter("campaignId", campaignId);
			List<String> queueObjectList = (List<String>) q.getResultList();
			return queueObjectList;
		} catch (Exception e) {
			e.printStackTrace();
			throw new EaoExcepcion(e.getMessage());
		}
		
	}

}
